﻿using System;
using System.Data;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using FunkeLab;

namespace AnyOffice.general.hrms.query
{
    public partial class user_list : ModulePage
    {
        protected MyTreeViewItem nodeParent;

        private void LoadDeptTree(ref MyTreeViewItem nodeParent, int DeptId)
        {
            DataTable table = new DepartmentDao().SelectChildAll(base.Conn, DeptId);
            if (table.Rows.Count > 0)
            {
                for (int i = 0; i < table.Rows.Count; i++)
                {
                    MyTreeViewItem item = new MyTreeViewItem();
                    item.Text = (table.Rows[i]["DeptName"] == DBNull.Value) ? "" : table.Rows[i]["DeptName"].ToString();
                    item.Link = "dept.aspx?dept_id=" + table.Rows[i]["DeptId"].ToString();
                    item.TargetFrame = "hrms";
                    item.Image = "/images/node_dept.gif";
                    this.LoadDeptTree(ref item, int.Parse(table.Rows[i]["DeptId"].ToString()));
                    nodeParent.Items.Add(item);
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                DataTable table = new DepartmentDao().SelectParentAll(base.Conn);
                if (table.Rows.Count > 0)
                {
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        this.nodeParent = new MyTreeViewItem();
                        this.nodeParent.Text = (table.Rows[i]["DeptName"] == DBNull.Value) ? "" : table.Rows[i]["DeptName"].ToString();
                        this.nodeParent.Link = "dept.aspx?dept_id=" + table.Rows[i]["DeptId"].ToString();
                        this.nodeParent.TargetFrame = "hrms";
                        this.nodeParent.Image = "/images/node_dept.gif";
                        this.LoadDeptTree(ref this.nodeParent, int.Parse(table.Rows[i]["DeptId"].ToString()));
                        this.TreeView1.Items.Add(this.nodeParent);
                    }
                }
            }
        } 

    }
}
